﻿@using MFTool;
<div class="formBottomToolBar">
    @* 签字意见 *@
    @if (ViewBag.bUserComment)
    {
        <form style="padding-top:5px;padding-left:5px">
            <input id='UserComment' name='UserComment' class='easyui-textbox' data-options="prompt:'意见填写',height:'65',required:true,multiline:true" style='width:99%;'>
        </form>
    }
    <div class="datagrid-toolbar" style="border-bottom:0px">
        @* 可否操作 *@
        @if (ViewBag.CanOperate)
        {
            @* 可否保存 *@
            if (ViewBag.CanSave)
            {
                <a href="#" class="easyui-linkbutton" plain="true" onclick="saveForm()" iconcls="iconfont iconfont-baocun">保存</a>
            }
            @* 可否撤回 *@
            if (ViewBag.CanWithdraw)
            {
                <a href="#" class="easyui-linkbutton" plain="true" onclick="withdraw()" iconcls="iconfont iconfont-chexiao">撤回</a>
            }
            @* 可否退回 *@
            if (ViewBag.CanGoBack)
            {
                <a href="#" class="easyui-linkbutton" plain="true" onclick="goBack()" iconcls="iconfont iconfont-xiangzuo">退回</a>
            }

            @* 下一个环节选择按钮 *@
            int index = 1;
            int personIconMax = 8;@* 见icon.css 的 icon-person *@

            foreach (MF_WorkFlow.Model.WFRoutingDefInst tmp in ViewBag.NextRoutingDefInstList)
            {
                string iconCls = "icon icon-person" + (index % personIconMax);
                index++;
                string isFinal = (tmp.E_WFNodeDefInst.WFNodeType == MF_WorkFlow.WFNodeType.End.ToString()).ToString().ToLower();
                string jsonStr = tmp.ToJson();
                <a href="#" class="easyui-linkbutton" plain="true"
                   onclick="saveFlow('@jsonStr','@isFinal')"
                   iconcls="@iconCls">@tmp.Name</a>
            }
        }

        @if (ViewBag.CanTrace)
        {
            <a href="#" class="easyui-linkbutton" plain="true" onclick="openTraceWindow()" iconcls="iconfont iconfont-jishiqi">流程跟踪</a>
        }
    </div>
</div>
<div style="padding:2px;">
    <form method="post" id="mf_form">
        @Html.Raw(ViewBag.FormHtml)
        @* 审批信息 *@
        @{
            var signDetail = ViewBag.SignDetail as List<Dictionary<string, object>>;
            if (signDetail != null && signDetail.Count > 0)
            {
                <table class="groupTable">
                    <tbody>
                        <tr class="title">
                            <td class="title" colspan="5">审批信息</td>
                        </tr>
                        @foreach (var sign in signDetail)
                        {
                            <tr>
                                <td style="width:15%" rowspan="3">@sign.GetValue("StepSign")</td>
                            </tr>
                            <tr style="height:50px">
                                <td colspan="4" style="vertical-align: top;height:50px">
                                    <div style="padding-left: 5px;">
                                        @sign.GetValue("Opinion")
                                    </div>
                                </td>
                            </tr>
                            <tr style="height:30px">
                                <td style="width:8%;font-weight:bolder;text-align:right">负责人签字：</td>
                                <td style="width:34%">@sign.GetValue("UserName")</td>
                                <td style="width:8%;font-weight:bolder;text-align:right">签字日期：</td>
                                <td style="width:35%">@sign.GetValue("OperateDate")</td>
                            </tr>
                        }
                    </tbody>
                </table>
            }
        }
    </form>
</div>

<script>
    var formId = '@ViewBag.FormId'
    var wFDefInstId = '@ViewBag.WFDefInstId'
    var id = queryString('Id');
    var currentStepId = '@ViewBag.CurrentStepId'

    //下一环节角色限定部分
    //角色限定
    var nextStepRoleIdArrStr = '@ViewBag.NextStepRoleIdArr';
</script>
<script type="text/javascript" src="@Url.Content("/BaseResource/Script/configui.js")"></script>
<script>
    @Html.Raw(ViewBag.Script)
    var bUserComment = '@Html.Raw(ViewBag.bUserComment)';
</script>
<script>
    function afterSetFormData() {
        if (bUserComment == 'True') {
            $('.formBottomToolBar + div').css('margin-bottom', '110px');
        }
        else {
            $('.formBottomToolBar + div').css('margin-bottom', '45px');
        }
    }

    function saveForm() {
        addAjaxParam("wFDefInstId", wFDefInstId);//流程定义实例Id
        save(true);
    }
    function saveFlow(wfRoutingDefInstStr, isFinal) {
        var wfRoutingDefInst = JSON.parse(wfRoutingDefInstStr);
        var routingDefInstId = wfRoutingDefInst.Id;
        var nextRoutingName = wfRoutingDefInst.Name;

        if (!validateFormData())
            return;

        if (routingDefInstId) {
            addAjaxParam("nextRoutingDefInstId", routingDefInstId);//下个节点
        }
        if (currentStepId) {
            addAjaxParam("currentStepId", currentStepId);//当前步骤
        }

        addAjaxParam("wFDefInstId", wFDefInstId);//流程定义实例Id
        addAjaxParam("formInstId", id);//表单实例(Entity)Id

        //结束环节
        if (isFinal == 'true') {
            confirmBox('是否【' + nextRoutingName + '】?', function (r) {
                if (r) {
                    save();
                }
            })
        }
        else {
            if (wfRoutingDefInst.IsDefineNextExcuteUsers) {
                commitAjax("GetNextExcuteUsers?routingDefInstId=" + routingDefInstId, {
                    notUsePostData: true,
                    CallBack: function (data) {
                        if (data && data.Id != '') {
                            confirmBox('是否发送给【' + data.Name + '】?', function (r) {
                                if (r) {
                                    addAjaxParam("nextUserId", data.Id);
                                    addAjaxParam("nextUserName", data.Name);
                                    save();
                                }
                            })
                        }
                        else {
                            confirmBox('无法找到接收人是否手动选择?', function (r) {
                                if (r) {
                                    openWindow('/AutoUI/Sys/MFUser/MultiSelector', {
                                        width: 700, height: 400,
                                        onDestroy: function (res) {
                                            if (res) {
                                                addAjaxParam("nextUserId", res.Id);
                                                addAjaxParam("nextUserName", res.RealName);
                                                save();
                                            }
                                        }
                                    });
                                }
                            })
                        }
                    }
                });
            }
            else {
                openWindow('/AutoUI/Sys/MFUser/MultiSelector', {
                    width: 700, height: 400,
                    onDestroy: function (res) {
                        if (res) {
                            addAjaxParam("nextUserId", res.Id);
                            addAjaxParam("nextUserName", res.RealName);
                            save();
                        }
                    }
                });
            }
        }
    }
    function openTraceWindow() {
        openWindow('/WorkFlow/WFForm/Trace?Id=' + id);
    }
    function goBack() {
        if ($('#UserComment').length > 0 && $('#UserComment').textbox('getValue') == '') {
            return msgBox('请填写意见');
        }

        confirmBox('是否退回?', function (r) {
            if (r) {
                addAjaxParam("currentStepId", currentStepId);
                if ($('#UserComment').length > 0)
                    addAjaxParam("userComment", $('#UserComment').textbox('getValue'));
                commitAjax("GoBack", {
                    CallBack: function (data) {
                        closeWindow(true);
                    }
                })
            }
        })
    }
    function withdraw() {

    }
</script>